package sky.mapper;

import com.sky.entity.AppUser;
import com.sky.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface UserMapper {
    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
    @Select("select * from user where openid=#{openid}")
    User getByOpenid(String openid);

    /**
     * 插入用户数据
     * @param user
     */
    void insert(User user);

    /**
     * 根据id查询用户
     * @param userId
     * @return
     */
    @Select("select * from user where id=#{userId}")
    User getById(Long userId);

    /**
     * 根据条件统计用户数量
     * @param map
     * @return
     */
    Integer countByMap(Map<String, Object> map);

    /**
     * 新增用户
     * @param appUser
     */
    @Insert("insert into app_user(username,password,phone,sex,nick,avatar,create_time) values(#{username},#{password},#{phone},#{sex},#{nick},#{avatar},#{createTime})")
    int insertAppUser(AppUser appUser);

    @Select("select * from app_user where username=#{username}")
    AppUser selectByAppUserName(String username);

    @Select("select * from app_user where id=#{id}")
    AppUser getAppUserById(Long id);

    void updateAppUser(AppUser appUser);
}
